package com.saunter.service.user;

import com.saunter.utils.CookieUtils;
import com.saunter.utils.encrypt.JavaWebToken;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

public class SuperUserService {
    protected String createAdminJwt(String key, String user_id) {
        Map<String, Object> jwt_token_claims = new HashMap<String, Object>();
        jwt_token_claims.put(key, user_id);
        return JavaWebToken.createJavaWebToken(user_id, jwt_token_claims);
    }
    public String getLoginId(String sid) {
        Object user_id_parse = JavaWebToken.parseJavaWebToken(sid, "user_id");
        return null != user_id_parse ? user_id_parse.toString() : null;
    }
    public String getLoginId(HttpServletRequest request) {
        String cookie_sid = CookieUtils.getCookie(request, "sid");
        return this.getLoginId(cookie_sid);
    }
}
